---
category: String
contributors:
    - mahdiyar
created: '2020-06-04'
title: Trim some character
updated: '2021-10-13'
---

**JavaScript version**

```js trim.js
const trim = (str, char) => str.split(char).filter(Boolean).join();
```

**TypeScript version**

```ts trim.ts
const trim = (str: string, char: string): string => str.split(char).filter(Boolean).join();
```

**Examples**

```js examples.js
trim('/hello world//', '/'); // hello world
trim('"hello world"', '"'); // hello world
trim('   hello world ', ' '); // hello world
```
